package impl.gui;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class UDecideLogPanel extends JPanel {

	private static UDecideLogPanel	instance;

	private JTextArea					log;

	public void info(String s) {
		this.log.append(getCurrentTimeStamp() + " --> " + s + "\n");
	}

	public void warning(String s) {
		this.log.append(getCurrentTimeStamp() + " --> Warning: " + s + "\n");
	}

	public void error(String s) {
		this.log.append(getCurrentTimeStamp() + " --> Error: " + s + "\n");
	}

	public UDecideLogPanel() {
		instance = this;

		this.log = new JTextArea() {
			{
				setOpaque(false);
			}

			@Override
			public void paintComponent(final Graphics g) {
				try {
					Image image = new ImageIcon(this.getClass().getResource("/logo.png")).getImage();
					g.drawImage(image, (getWidth() / 2) - (image.getWidth(this) / 2), (getHeight() / 2) - (image.getHeight(this) / 2), this);
					super.paintComponent(g);
				} catch (Exception e) {

				}
			}
		};
		this.log.setLineWrap(true);

		this.setLayout(new BorderLayout());
		this.add(this.log, BorderLayout.CENTER);
	}

	public static UDecideLogPanel getInstance() {
		return instance;
	}

	private static String getCurrentTimeStamp() {
		SimpleDateFormat sdfDate = new SimpleDateFormat("HH:mm:ss");
		Date now = new Date();
		String strDate = sdfDate.format(now);
		return strDate;
	}

}
